package edu.unc.comp410.colemangeer.data;

import java.io.*;
import java.util.*;
import java.util.HashMap;

public class MinMaxLoader {
	
	//declarations
	private static String INPUT_FILE_LOCATION = "resources/";
	private static String INPUT_FILE_NAME = "min_max_values.in";
	private String inputFile = INPUT_FILE_LOCATION + INPUT_FILE_NAME;
	private HashMap<String,Integer> constraintMinMap = new HashMap<String,Integer>();
	private HashMap<String,Integer> constraintMaxMap = new HashMap<String,Integer>();
	
	//constructor
	public MinMaxLoader() throws FileNotFoundException {
		loadFromFile(inputFile);
	}
	
	
	//getters
	public Integer getMinValue( String theConstraintName ){		
		Integer result = constraintMinMap.get(theConstraintName);
		return result;
	}
	
	public Integer getMaxValue( String theConstraintName ){		
		Integer result = constraintMaxMap.get(theConstraintName);
		return result;
	}
	
	
	//pick up the min/max file 
	public void loadFromFile( String inputFile ) throws FileNotFoundException {
		Scanner inp = new Scanner( new File( inputFile ) );
		while( inp.hasNext() ) {
			String line = inp.nextLine();
			String[] field = line.split(" ");
			
			String constraintName = field[0];
			String requiredVar = field[1];
			Integer minVar = Integer.parseInt(field[2]);
			Integer maxVar = Integer.parseInt(field[3]);
			
			constraintMinMap.put(constraintName, minVar);
			constraintMaxMap.put(constraintName, maxVar);
			
			//System.out.print( constraintName );
			//System.out.print(" min is: *" + getMinValue( constraintName ) + "* ");
			//System.out.println("max is: *" + getMaxValue( constraintName ) + "*");
		}
	}

}
